<template>
    <Layout>
        <Form ref="queryForm" :model="dataToQuery" :label-width="120">
            <Row  class="query-form">
                <Col span="8">
                    <FormItem label="培训方式：">
                        <Select v-model='dataToQuery.trainingMethods' class="query-form-el">
                           <!-- <Option value="视频讲座">视频讲座</Option>
                            <Option value="口述">口述</Option>
                            <Option value="观看视频">观看视频</Option>
                            <Option value="互动讨论">互动讨论</Option>
                            <Option value="实践练习">实践练习</Option>-->
                            <Option v-for="item in trainingMethodsMap" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName }}</Option>
                        </Select>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="培训主题：">
                        <Input class='query-form-el' type='text' v-model='dataToQuery.trainingTopics'/>
                    </FormItem>
                </Col>
                <Col span="8" v-if="!switchFlag">
                    <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
                    <Button @click="reset1" class="ivu-btn-reset">重置</Button>
                    <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
                <Col span="8" v-else>
                   <FormItem label='培训时间：'>
                       <DatePicker class="query-form-el" v-model="dataToQuery.trainingTimeRange" format="yyyy-MM-dd" type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                   :clearable="false" @on-change="(date) => onSelectFieldQueryDateRange(date, 'trainingTime')"></DatePicker>
                   </FormItem>
                </Col>
            </Row>
            <Row v-if="switchFlag" class="query-form">
                <Col span="8">
					<FormItem label="所属单位：">
					    <cascaderDom ref="queryOrgCascader" @setOrgInfo="setOrgId" @setOrgname="setOrgName"
					                 :rootOrgId="companyId" class="query-form-el"
					                 :orgTree="true"></cascaderDom>
					</FormItem>
                </Col>
				<Col span="8" >
				    <FormItem label="包含下级单位：" >
				        <RadioGroup v-model="dataToQuery.ifSelfUnit">
				            <Radio label="是">是</Radio>
				            <Radio label="否">否</Radio>
				        </RadioGroup>
				    </FormItem>
				</Col>
                <Col span="8" >
                    <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                    <Button @click="reset1" class="ivu-btn-reset">重置</Button>
                    <Button type="primary" class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                    <download-button :api="exportUrl" :query-form="dataToQuery"/>
                    <Button v-if="currentDetailVisible"  size="large" class="ivu-btn-add" icon="md-cloud-upload" @click="returnStatistic">返回</Button>
                </Col>
            </Row>
        </Form>
        <Table ref='table' v-if="!currentDetailVisible"  :height="tableHeight" no-data-text="没有查询到相关数据!"
               :loading='pageStatus.loading'
               border :columns="columns0" :data="dataTable">
        </Table>
        <Table ref='table' v-else :height="tableHeight" no-data-text="没有查询到相关数据!"
               :loading='loading'
               border :columns="columns1" :data="detailDataTable">
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page  v-if="!currentDetailVisible"  style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize"
                      @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
                <Page v-else style="float: right" :total="detailPagedata.total" :page-size="detailPagedata.pageSize"
                      @on-change="detailPageChange" @on-page-size-change="detailPageSizeChange" :page-size-opts="detailPageSizeArray"
                      show-total show-sizer show-elevator/>
            </Col>
        </Row>
        <Modal :title="getModalTitle('培训记录表')" :transfer=false :mask-closable="false" v-model="dialogShow" v-if="dataToView && dialogShow" :width=800
               :styles="{height:'559px'}"  class-name='limit-height-dialog'>
            <Form ref="dialogForm" :class="mode === 'view'?'modal-view-detail':'modal-form'"
                  :show-message="false" :model="dataToView" :rules="mode === 'view'?{} :ruleCustom"
                  :label-position="mode === 'view'?'right':'top'" :label-width="mode === 'view'?130:null">
                <Row type="flex" justify="space-around" class="code-row-bg">
                	<Col span="23">
                	  <FormItem label='企业名称：' prop='companyId'>
                	    <div v-if="mode === 'view'">{{dataToView.companyName}}</div>
                	    <cascader-dom v-else ref='orgCascader' @setOrgInfo='setCompanyId' @setOrgname="setCompanyName" :orgTree="true" :currentOrgId = "dataToView.companyId"
                	                  :setCurrentName="{label:dataToView.companyName,value:dataToView.companyId}" ></cascader-dom>
                	  </FormItem>
                	</Col>
                </Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label='培训主题：' prop='trainingTopics'>
                            <div v-if="mode === 'view'">{{ dataToView.trainingTopics }}</div>
                            <Input v-else class='query-form-el' placeholder="请填写培训主题" type='text' v-model='dataToView.trainingTopics'></Input>
                        </FormItem>
                    </Col>
                    <Col span="11">
                      <FormItem label='培训类型 ：' prop='trainingType'>
                        <div v-if="mode === 'view'">{{ this.trainingTypesMap[dataToView.trainingType] && this.trainingTypesMap[dataToView.trainingType].codingName }}</div>
                        <Select v-else v-model='dataToView.trainingType' class='query-form-el'>
                          <Option v-for="item in trainingTypesMap" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName }}</Option>
                        </Select>
                      </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label='培训时间：' prop='trainingTime'>
                            <div v-if="mode === 'view'">{{ renderViewDate(dataToView.trainingTime) }}</div>
                            <DatePicker v-else class="query-form-el" placeholder="请选择培训时间" v-model='dataToView.trainingTime' ></DatePicker>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label='培训地点：' prop='trainingLocation'>
                            <div v-if="mode === 'view'">{{ dataToView.trainingLocation }}</div>
                            <Input v-else class='query-form-el' placeholder="请填写培训地点" type='text' v-model='dataToView.trainingLocation'></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label='培训方式 ：' prop='trainingMethods'>
                            <div v-if="mode === 'view'">{{ this.trainingMethodsMap[dataToView.trainingMethods] && this.trainingMethodsMap[dataToView.trainingMethods].codingName }}</div>
                            <!--<Input v-else class='query-form-el' placeholder="请填写培训方式 " type='text' v-model='dataToView.trainingMethods'></Input>-->
                            <Select v-else v-model='dataToView.trainingMethods' class='query-form-el'>
                                <!--<Option value="视频讲座">视频讲座</Option>
                                <Option value="口述">口述</Option>
                                <Option value="观看视频">观看视频</Option>
                                <Option value="互动讨论">互动讨论</Option>
                                <Option value="实践练习">实践练习</Option>-->
                                <Option v-for="item in trainingMethodsMap" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label='主讲人：' prop='speaker'>
                            <div v-if="mode === 'view'">{{ dataToView.speaker }}</div>
                            <Input v-else class='query-form-el' placeholder="请填写主讲人" type='text' v-model='dataToView.speaker'></Input>
                        </FormItem>
                    </Col>
                </Row>
				<Row type="flex" justify="space-around" class="code-row-bg">
				    <Col span="11">
				        <FormItem label='培训课时：' prop='trainingHours'>
				            <div v-if="mode === 'view'">{{ dataToView.trainingHours }}</div>
				            <InputNumber v-else class="w" :active-change='false' :min="0" :precision="1" type='text' v-model='dataToView.trainingHours'></InputNumber>
				        </FormItem>
				    </Col>
					<Col span="11">
					  <FormItem label='培训人数：' prop='trainingNumber'>
					    <div v-if="mode === 'view'">{{dataToView.trainingNumber}}</div>
					    <InputNumber v-else class="w" :min="1"  type='text' v-model='dataToView.trainingNumber'></InputNumber>
					  </FormItem>
					</Col>
				</Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="23">
                        <FormItem label='培训记录：' prop='trainingContent'>
                            <div v-if="mode === 'view'">{{ dataToView.trainingContent }}</div>
                            <Input v-else class='query-form-el' placeholder="请填写培训记录" type='textarea' :autosize="{minRows:2,maxRows:5}" v-model='dataToView.trainingContent'></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around">
                    <Col span="23">
                        <FormItem v-if="mode === 'view'" label="签到附件：">
                            <div v-show="dataToView.idFiles.length>0" v-for="item in dataToView.idFiles">
                                <a @click="downloadFile(item)"><span style="color: #3399ff;margin-left: 5px">{{ item.fileName }}</span></a>
                            </div>
                        </FormItem>
                        <FormItem v-else label="上传签到附件：" prop="idFiles">
                            <div >
                                <Upload ref="upload"
                                        :before-upload="(file) => { beforeUpload(file, 'id') }"
                                        :show-upload-list="true"
                                        :max-size="10240"
                                        multiple
                                        type="drag"
                                        :action="fileUrl">
                                    <div style="padding: 20px">
                                        <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
                                        <p>点击将文件拖拽到这里上传</p>
                                    </div>
                                </Upload>
                            </div>
                            <div v-show="dataToView.idFiles.length>0" v-for="item in dataToView.idFiles">
                                <a @click.prevent="downloadFile(item)">{{item.fileName}}</a>
                                <Button type="text" icon="md-trash" @click="removeFile(item.id, 'id')"
                                        style="margin-left: 20px;margin-bottom: 3px"/>
                            </div>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label='评价方式：' prop='evaluationMethod'>
                            <div v-if="mode === 'view'">{{ this.evaluationMethodMap[dataToView.evaluationMethod] && this.evaluationMethodMap[dataToView.evaluationMethod].codingName  }}</div>
                            <Select v-else v-model='dataToView.evaluationMethod' class='query-form-el'>
                              <!--  <Option value="现场听课">现场听课</Option>
                                <Option value="考试">考试</Option>
                                <Option value="评议">评议</Option>
                                <Option value="问卷调查">问卷调查</Option>-->
                                <Option v-for="item in evaluationMethodMap" :value="item.codingCodeId" :key="item.codingCodeId">{{ item.codingName }}</Option>
                            </Select>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label='评价人：' prop='evaluationUser'>
                            <div v-if="mode === 'view'">{{ dataToView.evaluationUser }}</div>
                            <Input v-else class='query-form-el' placeholder="请填写评价人" type='text' v-model='dataToView.evaluationUser'></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label='综合得分：' prop='comprehensiveScore'>
                            <div v-if="mode === 'view'">{{ dataToView.comprehensiveScore }}</div>
                            <InputNumber v-else class='query-form-el' placeholder="请填写综合得分" :min="0" v-model='dataToView.comprehensiveScore'></InputNumber>
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label='评价结论：' prop='conclusion'>
                            <div v-if="mode === 'view'">{{ dataToView.conclusion }}</div>
                            <!--<Input v-else class='query-form-el' placeholder="请填写评价结论" type='text' v-model='dataToView.conclusion'></Input>-->
                            <Select v-else v-model='dataToView.conclusion' class='query-form-el'>
                                <Option value="效果显著">效果显著</Option>
                                <Option value="比较理想">比较理想</Option>
                                <Option value="效果一般">效果一般</Option>
                                <Option value="没达到预期效果">没达到预期效果</Option>
                                <Option value="效果不理想">效果不理想</Option>
                            </Select>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="11">
                        <FormItem label='记录人：' prop='createUserName'>
                            <div v-if="mode === 'view'">{{ dataToView.createUserName }}</div>
                            <Input v-else readonly class='query-form-el'  type='text' v-model='dataToView.createUserName'></Input>
                        </FormItem>
                    </Col>
                    <Col span="11">

                    </Col>
                </Row>
            </Form>
            <div slot="footer">
                <Button v-if="mode != 'view'" type="primary" class='ivu-btn-save' @click="submit('dialogForm')">确定
                </Button>
                <Button v-if="mode != 'view'" type="primary" class='ivu-btn-cancel' @click="handleCancel">取消</Button>
                <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
            </div>
        </Modal>

    </Layout>
</template>

<script>
    import {Api} from '../../../api/index.js'
    var cascaderDom = () => import('@/components/cascader-dom.vue');
    import {sessionStorage, cookie} from '@/common/cacheUtils.js';
    import pageCommonFunction from '@/components/pageCommonFunction.js'

    export default {
        components: {cascaderDom},
        data() {
            return {
                ...this.createCommonDataField(),
                loading:false,
                currentCompanyName:'',
                detailPageSizeArray: [10, 20, 50],
                detailDataTable:[],
                detailPagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                currentDetailVisible:false,
                columns0:[
                    { title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
                    { key:'companyName',title: '企业名称',minWidth: 150,  align: 'center' },
                    { key:'anquanSize',title: '安全培训数量',minWidth: 150,  align: 'center' },
                    { key:'huanbaoSize',title: '环保培训数据',minWidth: 150,  align: 'center' },
                    { key:'wangluoSize',title: '网络视频讲座数量',minWidth: 150,  align: 'center' },
                    { key:'mianshouSize',title: '面授数量',minWidth: 150,  align: 'center' },
                    { key:'shipinSize',title: '观看视频数量',minWidth: 150,  align: 'center' },
                    { key:'hudongSize',title: '互动讨论数量',minWidth: 150,  align: 'center' },
                    { key:'shijianSize',title: '实践练习数量',minWidth: 150,  align: 'center' },
                    {
                        title: '操作',
                        align: 'center',
                        key: 'view',
                        fixed: 'right',
                        width: 200,
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px'
                                    },
                                    on: {
                                        click: () => {
                                            this.showDetailData(params.row.companyName);
                                        }
                                    }
                                }, '详情')
                            ]);
                        }
                    }
                ],
                columns1: [
                    {title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
                    { key:'companyName',minWidth: 200,title: '企业名称',  align: 'center' },
					{ key:'trainingTopics',minWidth: 150,title: '培训主题',  align: 'center',tooltip:true },
					{ key:'trainingType',minWidth: 150,title: '培训类型',  align: 'center',render:(h, params)=>{
            return h('span', this.trainingTypesMap && this.trainingTypesMap[params.row.trainingType] && this.trainingTypesMap[params.row.trainingType].codingName)
          }, },
                    { key:'trainingTime',minWidth: 150,title: '培训时间',  align: 'center' ,render: this.renderCellDate},
                    { key:'trainingLocation',minWidth: 150,title: '培训地点',  align: 'center',tooltip:true },
                    { key:'trainingMethods',minWidth: 150,title: '培训方式 ',  align: 'center',render:(h, params)=>{
                            return h('span', this.trainingMethodsMap && this.trainingMethodsMap[params.row.trainingMethods] && this.trainingMethodsMap[params.row.trainingMethods].codingName)
                        }, },
                    { key:'speaker',minWidth: 150,title: '主讲人',  align: 'center' },
                    { key:'trainingContent',minWidth: 150,title: '培训记录',  align: 'center' ,tooltip:true},
                    { key: 'trainingNumber', title: '培训人数', align: 'center', width: 130 },
                    { key: 'trainingHours', title: '培训课时', align: 'center', width: 130 },
					{ key:'evaluationMethod',minWidth: 150,title: '评价方式',  align: 'center',render:(h, params)=>{
                            return h('span', this.evaluationMethodMap && this.evaluationMethodMap[params.row.evaluationMethod] && this.evaluationMethodMap[params.row.evaluationMethod].codingName)
                        },  },
                    { key:'comprehensiveScore',minWidth: 150,title: '综合得分',  align: 'center' },
                    { key:'evaluationUser',minWidth: 150,title: '评价人',  align: 'center' },
                    { key:'conclusion',minWidth: 150,title: '评价结论',  align: 'center' },
                    { key:'createUserName',minWidth: 150,title: '记录人',  align: 'center' },
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 180,
                        align: 'center',
                        render: (h, params) => {
                            if (params.row.id === '-1') return h('span','')
                            return h('div', [
                                h('A', {
                                    props: {type: 'primary', size: 'small'},
                                    style: {fontSize: '14px',},
                                    on: {
                                        click: () => {
                                            this.viewData(params);
                                        }
                                    }
                                }, '详情'),
                                h('Divider', {props: {type: 'vertical'}}, ''),
                                h('A', {
                                    props: {type: 'primary', size: 'small'},
                                    style: {fontSize: '14px',
                                        color: params.row.createUserId == sessionStorage('userId').getObject('userId').userId ||  this.Common.userIdList.includes(sessionStorage('userId').getObject('userId').userId ) || (sessionStorage('userId').getObject('userId').userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                                            ||sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined) ? '':'#d0d0d0' ,
                                        pointerEvents: params.row.createUserId == sessionStorage('userId').getObject('userId').userId ||  this.Common.userIdList.includes(sessionStorage('userId').getObject('userId').userId ) || (sessionStorage('userId').getObject('userId').userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                                            ||sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined) ? '' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.editData(params);
                                        }
                                    }
                                }, '修改'),
                                h('Divider', {props: {type: 'vertical'}}, ''),
                                h('A', {
                                    props: {type: 'primary', size: 'small'},
                                    style: {fontSize: '14px',
                                        color: params.row.createUserId == sessionStorage('userId').getObject('userId').userId ||  this.Common.userIdList.includes(sessionStorage('userId').getObject('userId').userId ) || (sessionStorage('userId').getObject('userId').userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                                            ||sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined)? 'red':'#d0d0d0' ,
                                        pointerEvents: params.row.createUserId == sessionStorage('userId').getObject('userId').userId ||  this.Common.userIdList.includes(sessionStorage('userId').getObject('userId').userId ) || (sessionStorage('userId').getObject('userId').userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                                            ||sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined)? '' : 'none'
                                    },
                                    on: {
                                        click: () => {
                                            this.deleteData(params);
                                        }
                                    }
                                }, '删除')
                            ])
                        }
                    }
                ],
                ruleCustom: {
					companyId: [ { required: true, message: '请选择企业名称', trigger: 'change'}],
                    trainingTopics: [ { required: true, message: '请填写培训主题', trigger: 'change',}],
                    trainingTime: [ { required: true, message: '请填写培训时间', trigger: 'change',type:'date'}],
                    trainingLocation: [ { required: true, message: '请填写培训地点', trigger: 'change',}],
                    trainingMethods: [ { required: true, message: '请填写培训方式 ', trigger: 'change',}],
                    trainingType:  [ {
                      validator: (rule, value, callback) => {
                        if (value == null || value == '' || value == undefined) {
                          callback(' ')
                        } else {
                          callback()
                        }
                      },
                      required: true,
                      trigger: 'change'
                    }],
                    speaker: [ { required: true, message: '请填写主讲人', trigger: 'change',}],
                    trainingContent: [ { required: true, message: '请填写培训内容', trigger: 'change',}],
                    evaluationMethod: [ { required: true, message: '请填写评价方式', trigger: 'change',}],
                    comprehensiveScore: [ {
                        validator: (rule, value, callback) => {
                            if (value == null || value == '' || value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    evaluationUser: [ { required: true, message: '请填写评价人', trigger: 'change',}],
                    conclusion: [ { required: true, message: '请填写评价结论', trigger: 'change',}],
					trainingNumber:[ { required: true, message: '请填写培训人数', trigger: 'change',type: 'number',}],
					trainingHours:[ { required: true, message: '请填写培训课时', trigger: 'change',type: 'number',}],
					idFiles:[{
						validator:(rule, value, callback) =>{
							if(this.dataToView.idFiles == undefined || this.dataToView.idFiles.length == 0){
								callback(' ')
							}else{
								callback()
							}
						},
						required: true,
						message: '请上传附件',
						trigger: 'change'
					}],
                },
                tableHeight: 10,
                companyId:'',
				idFiles:[],
                trainingMethodsMap:{},
                evaluationMethodMap:{},
              trainingTypesMap:{},
                // api
                exportUrl: Api.exportTrainingRecords,
                queryUrl: Api.queryTrainingRecords,
                deleteUrl: Api.deleteTrainingRecords,
                updateUrl: Api.updateTrainingRecords,
                saveUrl: Api.saveTrainingRecords,
            }
        },
        async mounted() {
			this.dataToQuery.ifSelfUnit = '是';
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            await this.$http.get(Api.queryCodeDetailBySortId + '/TRA-000003', {params: {}}).then((res) => {
                this.trainingMethodsMap = this.dictListToMap(res.data.data);
            });
            await this.$http.get(Api.queryCodeDetailBySortId + '/TR-000001', {params: {}}).then((res) => {
                this.trainingTypesMap = this.dictListToMap(res.data.data);
            });
            await this.$http.get(Api.queryCodeDetailBySortId + '/TRA-000004', {params: {}}).then((res) => {
                this.evaluationMethodMap = this.dictListToMap(res.data.data);
            });
            // console.log(window.innerHeight)
            // console.log(this.$refs)
            // console.log(this.$refs.table)
            this.companyId=sessionStorage('userId').getObject('userId').companyId
            this.query();
        },
        methods: {
            ...pageCommonFunction,
            deleteData(params) {
                this.deleteDateAjax(params);
            },
			reset1(){
				this.dataToQuery = {};
				this.dataToQuery.ifSelfUnit = '是'
				if (!this.currentDetailVisible && this.$refs.queryOrgCascader) {
				    this.$refs.queryOrgCascader.resetCurrentOrg();
				}
				this.pagedata.currentPage=1
				this.query()
			},
            query() {
				this.dataToQuery.orgId = sessionStorage('userId').getObject('userId').companyId //orgInfo.parentId
				if (this.dataToQuery.ifSelfUnit == '否') {
					this.dataToQuery.checkCompanyId = this.dataToQuery.companyId || this.dataToQuery.orgId;
				} else{
					this.dataToQuery.checkCompanyId = ''
				}
              if(this.dataToQuery.year != undefined && this.dataToQuery.year != ""){
                let date = new Date(this.dataToQuery.year);
                this.dataToQuery.year = date.getFullYear() + "";
              }
                this.currentDetailVisible
                ? this.queryDetail(this.currentCompanyName)
                : this.queryAjax();
            },
            submit(name) {
				if(this.dataToView.trainingNumber == '')  this.dataToView.trainingNumber = 1;
				if(this.dataToView.trainingHours == '')  this.dataToView.trainingHours = 0;
                this.submitAjax(name);
            },
            /*async beforeEditDialogOpen(data) {
                data.row.resWorks=data.row.resWork.split(',')
            },*/
            createEmptyDataToAdd() {
                return {
                    id:this.get_uuid(),
                    createUserName:sessionStorage('userId').getObject('userId').userName,
                    createUserId: sessionStorage('userId').getObject('userId').userId,
                    comprehensiveScore:null,
					trainingNumber:1,
					trainingHours:0,
                }
            },
            async afterDataToViewInit() {
                await this.getFiles('id');
            },
            setOrgId(data) {
                this.dataToQuery.companyId = data[data.length - 1];
            },
            setOrgName(data) {
                this.dataToQuery.orgName = data;
            },
            returnStatistic(){
                this.currentDetailVisible = false;
                this.loading = false;
            },
            detailPageChange(pageNum) {
                this.detailPagedata.currentPage = pageNum;
                this.queryDetail(this.currentCompanyName);
            },
            detailPageSizeChange(pageSize) {
                this.detailPagedata.pageSize = pageSize;
                this.queryDetail(this.currentCompanyName);
            },
            showDetailData(currentCompanyName){
                this.currentDetailVisible = true;
                this.currentCompanyName = currentCompanyName;
                this.queryDetail(currentCompanyName);
            },
            queryDetail(companyName) {
                this.loading = true;
              let index1=companyName.indexOf('(')
              let index2=companyName.indexOf(')')
              if(index1 != -1) {
                this.dataToQuery.orgName = companyName.substring(index1 + 1, index2)
              }else {
                this.dataToQuery.orgName = companyName;
              }
                let data = {
                    startPage: this.detailPagedata.currentPage,
                    size: this.detailPagedata.pageSize,
                    conditions: this.dataToQuery
                }
                let url = Api.queryTrainingRecordsByCompanyId;
                this.$http.post(url, data).then((res) => {
                    this.detailDataTable = res.data.data.data;
                    this.detailPagedata.total = res.data.data.totalSize;
                    this.loading = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
        },
        computed: {},

    }
</script>

<style lang='css' scoped>
    @import '../../../index.css';
</style>
